package net.lcheng.sellerCenter.controller;

import net.lcheng.commons.utils.PageList;
import net.lcheng.model.User;
import net.lcheng.model.UserAccountDetails;
import net.lcheng.model.UserWithdrawalsRecord;
import net.lcheng.service.BaseAreasService;
import net.lcheng.service.UserAccountDetailsService;
import net.lcheng.service.UserService;
import net.lcheng.service.UserWithdrawalsRecordService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * Created by zwr on 2016/7/8 0008.
 */
@Controller
public class UserAccountDetailsController {
    @Autowired
    private BaseAreasService baseAreasService;
    @Autowired
    private UserService userService;
    @Autowired
    private UserWithdrawalsRecordService userWithdrawalsRecordService;
    @Autowired
    private UserAccountDetailsService userAccountDetailsService;
    private final int PAGESIZE = 10;
    /**账号明细*/
    @RequestMapping(value = "user/account_details", method = RequestMethod.GET)
    public String userWalletDetailGet(Model model, @RequestParam(defaultValue = "1", required = false) int page) {
        Subject currentUser= SecurityUtils.getSubject();
        if(currentUser.isAuthenticated()) {
            String userPhoneNum = currentUser.getSession().getAttribute("UserPhoneNum").toString();
            //获取用户信息
            User user = userService.getUserByPhone(userPhoneNum);
            model.addAttribute("user",user);
            //账号明细
            PageList<UserAccountDetails>userAccountDetailsPageList= userAccountDetailsService.getUserWalletDetailsByUserId(page, PAGESIZE,user.getUserId());
            model.addAttribute("userAccountDetailsPageList",userAccountDetailsPageList.list);
            model.addAttribute("pageIndex", page);
            model.addAttribute("totalPage", userAccountDetailsPageList.totalPage);
        }
        return "wallet_detail";
    }
    /**提现记录*/
    @RequestMapping(value = "user/withdrawals_recording", method = RequestMethod.GET)
    public String userWithdrawals(Model model, @RequestParam(defaultValue = "1", required = false) int page) {
        Subject currentUser = SecurityUtils.getSubject();
        if (currentUser.isAuthenticated()) {
            String userPhoneNum = currentUser.getSession().getAttribute("UserPhoneNum").toString();
            //获取用户信息
            User user = userService.getUserByPhone(userPhoneNum);
            model.addAttribute("user", user);
            //提现记录
            PageList<UserWithdrawalsRecord> userWithdrawalsRecordPageList = userWithdrawalsRecordService.getUserWithdrawalsRecordByUserId(page, PAGESIZE, user.getUserId());
            model.addAttribute("userWithdrawalsRecordPageList", userWithdrawalsRecordPageList.list);
            model.addAttribute("pageIndex", page);
            model.addAttribute("totalPage", userWithdrawalsRecordPageList.totalPage);
        }
        return "withdrawals";
    }

}
